//发起获取后台数据请求
// axios.get('/api/login')
// .then(result=>{
//     console.log(result);
// })
 
//表单的点击显示切换
const register = document.querySelector('.register'); 
const loginBox = document.querySelector('.login');
const registerA = document.querySelector('.register-a');
const loginA = document.querySelector('.login-a')
//注册
registerA.addEventListener('click',function(){
    register.style.display='none'
    loginBox.style.display='block'
})

//登录
loginA.addEventListener('click',function(){
    loginBox.style.display='none'
    register.style.display='block'
    
})

//给注册按钮绑定点击事件
register.querySelector('form').addEventListener('submit',function (e) {
    e.preventDefault()
    const data = $(this).serialize()
    axios.post('/api/register',data)
    .then(result=>{
        if (result.data.code===0) {
            toastr.success(result.data.message)
            registerA.click()
        }
    })

})
//给登录按钮绑定点击事件
loginBox.querySelector('form').addEventListener('submit',function (e) {
    e.preventDefault()
    const data = $(this).serialize()
    axios.post('/api/login',data)
    .then(result=>{
        if (result.data.code===0) {
        toastr.success(result.data.message)
        localStorage.setItem('upUp',result.data.token)
        setTimeout(() => {
            location.href='./index.html'
        }, 1000);
        }
        
    })

})